<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="author" content="seecen"/>
    <title>用户注册</title>
    <link rel="stylesheet" type="text/css" href="css/login.css">
    <script src="js/jquery-3.4.1.js"></script>

</head>
<body>
<form  id="myForm" method="post" action="${pageContext.request.contextPath}/regedit.do">
    <!--隐藏域-->
    <input type="hidden" id="codeHidden" value="">
    <div class="regist">
        <div class="regist_center">
            <div class="regist_top">
                <div class="left fl">会员注册</div>
                <div class="right fr"><a href="./index.html" target="_self">小米商城</a></div>
                <div class="clear"></div>
                <div class="xian center"></div>
            </div>
            <div class="regist_main center">
                <div class="username">用&nbsp;&nbsp;户&nbsp;&nbsp;名:&nbsp;&nbsp;<input class="shurukuang" type="text" name="username" id="name" onblur="checkname()" required="required" placeholder="请输入你的用户名"/><span id="msg">请不要输入汉字</span></div>
                <div class="username">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;<input class="shurukuang" type="password" name="password" id="password" required placeholder="请输入你的密码"/><span>请输入6位以上字符</span></div>

                <div class="username">确认密码:&nbsp;&nbsp;<input class="shurukuang" type="password" name="repassword" required placeholder="请确认你的密码"/><span>两次密码要输入一致哦</span></div>
                <div class="username">手&nbsp;&nbsp;机&nbsp;&nbsp;号:&nbsp;&nbsp;<input class="shurukuang" type="text" name="tel" id="tel" required placeholder="请填写正确的手机号"/><span>填写下手机号吧，方便我们联系您！</span></div>
                <div class="username">
                    <div style="float: left">验&nbsp;&nbsp;证&nbsp;&nbsp;码:&nbsp;&nbsp;<input class="yanzhengma" type="text" name="inCode"  class="tel" required placeholder="请输入验证码" style="width:105px"/></div>
                    <div  id="telCode" style="float: left">获取验证码</div>
                </div>
            </div>
            <div class="regist_submit">
                <input class="submit" type="button" onclick="register()" name="submit" required value="立即注册" >
            </div>

        </div>
    </div>
</form>

</body>
<script>
    function checkname(){
        const name = $(".shurukuang")[0].value;
        $.ajax({
            url: "/checkname.do",
            type: "post",
            contentType:'application/json;charset=UTF-8',
            data: JSON.stringify([name]),
            success:function (res){
                if(res==""){
                    $("#msg").html("用户已存在")
                    $("#msg").css("color","red")
                }else {
                    $("#msg").html("用户名未注册")
                    $("#msg").css("color","green")
                }
            }
        })
    }
    function register(){
        const name = $(".shurukuang")[0].value;
        const password1 = $(".shurukuang")[1].value;
        const password2 = $(".shurukuang")[2].value;
        if(password1.value !=password2.value){
        alert("两次密码不一致")
        return;
    }
    $.ajax({
        url:"/register.do",
        type:"post",
        data:JSON.stringify([name,password1]),
        contentType:'application/json;charset=UTF-8',
        success:function (res){
            alert(res)
            if(res=="success"){
                window.location.assign("login.jsp")
            }
        }
    })
}
</script>
</html>